--[[
 最简单的爬虫：从一个网站，抓取 image url，并下载到指定的目录
 
 luarocks install luasocket

--]]

-- goal 1 : simple get

Hello={}

local http = require('socket.http')
local ltn12 = require('ltn12')

function Hello.get (url)
    local t = {}
    local r,c,h = http.request({
        url = url,
        sink = ltn12.sink.table(t) 
        })
    return r,c,h,table.concat(t)
end

url = 'http://www.baidu.com'
r,c,h,body = Hello.get(url)
if c ~= 200 then
    return
end
print(body)
